/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lenovo
 * Date: 2025-07-27
 * Time: 22:54
 */
public class MySort {

    public static void fun(int[] arr,int i,int j){
        int n=arr[i];
        arr[i]=arr[j];
        arr[j]=n;
    }

    // 冒泡排序
    public static void bubbleSort(int[] arr){
        boolean n;
        for (int i=0;i<arr.length;i++){
            n=true;
            for (int j=1;j<arr.length-i;j++){
                if(arr[j-1]>arr[j]) {
                    fun(arr, j - 1, j);
                    n = false;
                }
            }
            if(n){
                break;
            }
        }
    }

    // 快速
    public static void quickSort(int[] arr){
        quick(arr,0,arr.length-1);
    }

    public static void quick(int[] arr,int n,int end){
        if(n>=end){
            return;
        }
        int o=arr[n];
        int k=n;
        int i=n;
        int j=end;
        while(i<j){
            while(i<j){
                if(arr[j]<o){
                    arr[k]=arr[j];
                    k=j;
                    break;
                }
                j--;
            }
            while(i<j){
                if(arr[i]>o){
                    arr[k]=arr[i];
                    k=i;
                    break;
                }
                i++;
            }
        }
        arr[i]=o;
        quick(arr,n,i-1);
        quick(arr,i+1,end);
    }
}
